<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String username=request.getParameter("name");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>talk.jsp</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="js/jquery.easyui.min.js" type="text/javascript"></script>
    <link href="css/easyui.css" rel="stylesheet" type="text/css" />
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<script type="text/javascript">

$.ajax({     
    //要用post方式      
    type: "post",     
    //方法所在页面和方法名      
    url: "<%=request.getContextPath() %>/index/timeselect.action", 
    data: {"timesenderId":<%=new String(request.getParameter("senderId").getBytes("ISO-8859-1"),"UTF-8")%>,"timereceiverId":<%=new String(request.getParameter("receiverId").getBytes("ISO-8859-1"),"UTF-8")%>}, 
    contentType: "application/x-www-form-urlencoded",     
    dataType: "json",     
    success: function(data) {  
     $.each(data,function(i,item){
   	
   	  if(item.msgType==1)
   		  {
   		
   		     var touxiang="http://192.168.1.200:8080/download/head_img/photo/"+item.senderfileUri+"/"+item.senderphotoname+".jpg";
   		
       	    $("#liaoTianContent").append("<li>"+"<img width=35px; src="+touxiang+">"+"<%=new String(request.getParameter("senderName").getBytes("ISO-8859-1"),"UTF-8")%>"+":"+item.text+"</li>");  
   		  }
   	  if(item.msgType==2)
   		  {
		        var touxiang="http://192.168.1.200:8080/download/head_img/photo/"+item.senderfileUri+"/"+item.senderphotoname+".jpg";
   		    var url="http://192.168.1.200:8080/msgdownload/photo/";
   	
       	    $("#liaoTianContent").append("<li>"+"<img width=35px; src="+touxiang+">"+"<%=new String(request.getParameter("senderName").getBytes("ISO-8859-1"),"UTF-8")%>"+":"+"<img width=100px; src="+url+item.fileUri+">"+"</li>");  
   		  }
   	  
	  });
    },     
    error: function(err) {     
    	alert("失败");
    }     
});
window.setInterval(timeselect, 60000); 
function timeselect()
{
    
	 $.ajax({     
         //要用post方式      
         type: "post",     
         //方法所在页面和方法名      
         url: "<%=request.getContextPath() %>/index/timeselect.action", 
         data: {"timesenderId":<%=new String(request.getParameter("senderId").getBytes("ISO-8859-1"),"UTF-8")%>,"timereceiverId":<%=new String(request.getParameter("receiverId").getBytes("ISO-8859-1"),"UTF-8")%>}, 
         contentType: "application/x-www-form-urlencoded",     
         dataType: "json",     
         success: function(data) {  
          $.each(data,function(i,item){
        	
        	  if(item.msgType==1)
        		  {
        		
        		     var touxiang="http://192.168.1.200:8080/download/head_img/photo/"+item.senderfileUri+"/"+item.senderphotoname+".jpg";
        		
            	    $("#liaoTianContent").append("<li>"+"<img width=35px; src="+touxiang+">"+"<%=new String(request.getParameter("senderName").getBytes("ISO-8859-1"),"UTF-8")%>"+":"+item.text+"</li>");  
        		  }
        	  if(item.msgType==2)
        		  {
     		        var touxiang="http://192.168.1.200:8080/download/head_img/photo/"+item.senderfileUri+"/"+item.senderphotoname+".jpg";
        		    var url="http://192.168.1.200:8080/msgdownload/photo/";
        	
            	    $("#liaoTianContent").append("<li>"+"<img width=35px; src="+touxiang+">"+"<%=new String(request.getParameter("senderName").getBytes("ISO-8859-1"),"UTF-8")%>"+":"+"<img width=100px; src="+url+item.fileUri+">"+"</li>");  
        		  }
        	  
     	  });
         },     
         error: function(err) {     
         	alert("失败");
         }     
     });  
	}
function tiJiao(senderId,receiverId){
    var uu="<%=new String(request.getParameter("photourl").getBytes("ISO-8859-1"),"UTF-8")%>";
	var test = document.getElementById("content");
	$("#liaoTianContent").append("<li>"+"<img src="+uu+">"+"<%=new String(request.getParameter("fakename").getBytes("ISO-8859-1"),"UTF-8")%>"+":"+test.value+"</li>");  
	//插入message表
	 $.ajax({     
         //要用post方式      
         type: "post",     
         //方法所在页面和方法名      
         url: "<%=request.getContextPath() %>/index/save.action", 
         data:  {"receiverId":senderId,"senderId":receiverId,"msgType":1,"origin":1,"text":test.value,"status":0}, 
         contentType: "application/x-www-form-urlencoded",     
         dataType: "json",     
         success: function(data) {  
           if(data=1)
        	   {
        	      //alert("发送成功"); 
        	   }
           if(data=0)
        	   {
        	     alert("发送失败"); 
        	   }
         },     
         error: function(err) {     
         	alert("失败");
         }     
     });
	
	 test.value="";
}

  function chaxun(senderId,receiverId)
  {
	
	 $.ajax({     
         //要用post方式      
         type: "post",     
         //方法所在页面和方法名      
         url: "<%=request.getContextPath() %>/index/chaxun.action", 
         data: {"senderId":senderId,"receiverId":receiverId}, 
         contentType: "application/x-www-form-urlencoded",     
         dataType: "json",     
         success: function(data) { 
        	 $("#ul").html('');
          $.each(data,function(i,item){
        	  
        	  if(item.msgType==1)
    		  {
        		  
            	  $("#ul").append("<li>"+item.senderName+"-"+item.receiverName+":"+item.text+"</li>"); 
    		  }
    	  if(item.msgType==2)
    		  {
    		   var url="http://192.168.1.200:8080/msgdownload/photo/";
        	     $("#ul").append("<li>"+item.senderName+"-"+item.receiverName+":"+"<img width=100px; src="+url+item.fileUri+">"+"</li>"); 
    		  }
        	  
     	  });
         },     
         error: function(err) {     
         	alert("失败");
         }     
     });  
 	
	}
  
  function clean()
  {
	  $("#ul").html('');
  }
</script>
      
     <style>
      body{
		font-size:18px;
		}
        ul{
           list-style-type:none;
        }
    </style>
  </head>
  
<body >

<table cellpadding="0" cellspacing="0" width="100%" style="font-size:10px">
	<tr>
		<td>
           <div>
              <ul id="liaoTianContent">
                  
              </ul>
           </div>
		</td>
	</tr>
	<tr>
		<td>
			<input style="width:600px;" type="text" id="content" name="content">
			<input type="button" onclick="tiJiao('<%=new String(request.getParameter("senderId").getBytes("ISO-8859-1"),"UTF-8")%>','<%=new String(request.getParameter("receiverId").getBytes("ISO-8859-1"),"UTF-8")%>')" value="提交">
			<input type="button" onclick="chaxun('<%=new String(request.getParameter("senderId").getBytes("ISO-8859-1"),"UTF-8")%>','<%=new String(request.getParameter("receiverId").getBytes("ISO-8859-1"),"UTF-8")%>')" value="查询历史记录">
		   <input type="button" onclick="clean()" value="清空历史记录">
		</td>
	</tr>
</table>
<div>
   <ul id="ul">
       
   </ul>
</div>
  </body>
</html>
